//package com.ugoodtech.mdcc.client.controller;
//
///* Copyright (C) Ugoodtech, Inc - All Rights Reserved
// * Unauthorized copying of this file, via any medium is strictly prohibited
// * Proprietary and confidential
// * Written by Stone Shaw, 15/11/19
// */
//
//
//import com.ugoodtech.mdcc.client.dto.JsonResponse;
//import com.ugoodtech.mdcc.core.service.impl.QiNiuService;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.stereotype.Controller;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RequestMethod;
//import org.springframework.web.bind.annotation.RequestParam;
//import org.springframework.web.bind.annotation.ResponseBody;
//import org.springframework.web.multipart.MultipartFile;
//import springfox.documentation.annotations.ApiIgnore;
//
//import javax.servlet.http.HttpServletResponse;
//import java.io.IOException;
//import java.util.HashMap;
//import java.util.Map;
//
//@ApiIgnore
//@Controller
//@RequestMapping("/qiNiu")
//public class QiNiuController {
//
//    @Autowired
//    QiNiuService qiNiuService;
//
//    @Value("${qiniu.bucketDomain}")
//    private String bucketDomain;
//
//    @RequestMapping(value = "/uploadFile", method = RequestMethod.POST)
//    @ResponseBody
//    public JsonResponse uploadFile(
//
//            @RequestParam(value = "file") MultipartFile file
//    ) throws Exception {
//        if (logger.isDebugEnabled()) {
//            logger.debug("--------------uploadFile---------------");
//
//            logger.debug("imageSize  = " + file.getSize());
//            logger.debug("imageOriginalFilename  = " + file.getOriginalFilename());
//            logger.debug("imageContentType : " + file.getContentType());
//        }
//
//        try {
//            String key = qiNiuService.upload(file.getBytes());
//            Map map = new HashMap<>();
//            map.put("key", key);
////            logger.debug("key : " + key);
//            return JsonResponse.successResponseWithData(map);
//        } catch (IOException e) {
//            e.printStackTrace();
//            logger.debug("上传失败，数据异常");
//            logger.debug("--------------------------------------");
//            return JsonResponse.errorResponseWithError("上传失败，数据异常", "上传失败，数据异常");
//        }
//
//
//    }
//
//
//    @RequestMapping("/getFileUrl")
//    @ResponseBody
//    public JsonResponse getPhoto(HttpServletResponse response,
//                                 @RequestParam(value = "key") String key,
//                                 @RequestParam(value = "width", required = false) Integer width,
//                                 @RequestParam(value = "height", required = false) Integer height) throws Exception {
//
//        String url = "";
//        if (null != width && null != height) {
//            url = qiNiuService.getPublicDownloadUrl(key, width, height);
//        } else {
//            url = qiNiuService.getPublicDownloadUrl(key);
//        }
//        Map map = new HashMap<>();
//        map.put("url", url);
////        logger.debug("url : " + url);
//        return JsonResponse.successResponseWithData(map);
//    }
//
//    @RequestMapping("/getQiNiuUrl")
//    @ResponseBody
//    public JsonResponse getQiNiuUrl() throws Exception {
//
//        String url = "http://" + bucketDomain + "/";
//
//        return JsonResponse.successResponseWithData(url);
//    }
//
//    Logger logger = LoggerFactory.getLogger(QiNiuController.class);
//}
